# coding=utf-8

from web import form

from i18n import _

vpass = form.regexp(r'^.{3,20}$', _(u'请输入密码，密码长度为3 - 20个字符'))
vemail = form.regexp(r'(?i)^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$', _(u'输入的E-mail格式错误'))


# TODO: EmailTextbox
class EmailTextbox(form.Input):
	def get_type(self):
		return 'email'

# TODO: 登录状态
login_form = form.Form(
	EmailTextbox('email'
		, vemail
		, required = 'required'
		, description = _(u'E-mail')
		, tabindex = 1),

	form.Password('password'
		, vpass
		, required = 'required'
		, description = _(u'密码')
		, tabindex = 2
		, minlenth = 3),
	
	form.Button('login_submit'
		, type = 'submit'
		, html = _(u'登入')),
)

# TODO: 注册表单
register_form = form.Form(
	EmailTextbox('email'
		, vemail
		, required = 'required'
		, description = _(u'E-mail')
		, tabindex = 1
		, maxlength = 32),

	form.Password('password'
		, vpass
		, required = 'required'
		, description = _(u'密码')
		, tabindex = 2
		, minlength = 3),

	form.Password('retype_password'
		, description = _(u'确认密码')
		, tabindex = 3
		, minlength = 3
		, data_equals = 'password'),

	form.Button('reg_submit'
			, type = 'submit'
			, html = _(u'确认')),

	validators = [
		form.Validator(_(u'密码与确认密码不一致'), lambda i: i.password == i.retype_password)]
)
